< previous page page_272 next page >

Page 272
0272-01.jpg
Figure 9.13
A screen saver should display a preview when it receives the /p flag.
When Windows passes the program the /p flag, it also passes the preview window's window handle. The screen saver should draw its preview on that window. For example, if the program receives the command string ''/p 787482," it should display its preview on the window with window handle 787482.
This is not hard if the program normally draws using the API. The program can use the GetDC API function to get the window's device context handle and then use API functions to draw on that device context.
In Visual Basic, drawing using the API functions is inconvenient. It is much easier to use Visual Basic's Line, Circle, and other drawing methods. With a little creative API use, you can display the preview using normal Visual Basic methods.
First, load the drawing form on which the program draws its animation. Use GetWindowLong to get the form's window style. Add the WS_CHILD style to this value and set the form's new style using SetWindowLong. This converts the form so that you can display it inside another window.
Next, break the preview window handle out of the command string. Use SetParent to make the drawing form have as its parent the preview window. Use SetWindowLong to save the preview window's handle in the drawing window's GWL_HWNDPARENT entry. At this point, the drawing window is an official child of the preview area.
Use the GetClientRect API function to get the preview window's dimensions. Finally, use SetWindowPos to make the drawing window fill the preview window.

 
< previous page page_272 next page >